Added test cases related to database operations - #11
Conversation
gburd
left a comment
There was a problem hiding this comment.
Thanks for the contribution, and for thinking about boundary/cursor/stat coverage — that kind of testing is welcome.
Unfortunately I can't merge this as-is: it won't compile. test/c/test_db185.c exercises the DB 1.85 compatibility API (it #includes db_185.h and dbp is the 1.85 DB). That handle is defined in src/dbinc/db_185.in and has only these methods:
typedef struct __db {
DBTYPE type;
int (*close)(struct __db *);
int (*del)(const struct __db *, const DBT *, u_int);
int (*get)(const struct __db *, const DBT *, DBT *, u_int);
int (*put)(const struct __db *, DBT *, const DBT *, u_int);
int (*seq)(const struct __db *, DBT *, DBT *, u_int);
int (*sync)(const struct __db *, u_int);
void *internal;
int (*fd)(const struct __db *);
} DB;So the new code can't build here:
dbp->cursor(...)anddbp->stat(...)— no such members on the 1.85DB.cursor->c_get/c_put/c_close(DBC), and constantsDB_NEXT,DB_SET,DB_KEYFIRST,DB_NOTFOUND,DB_BTREE_STAT/DB_HASH_STAT/DB_RECNO_STAT— these are the modern API, not indb_185.h(the 1.85 API iterates withseq()+R_NEXT/R_FIRSTand has no cursors or stat).
A couple of other issues to flag regardless:
char large_key[1024*1024]is a 1 MB stack array (stack overflow risk).- In
test_db_cursor,sprintf((char *)key.data, ...)writes into the buffer returned byc_get, which is owned by Berkeley DB — that's a write into library-owned memory.
Two good ways forward:
- Best: add these cursor/stat/boundary tests against the modern API — e.g. a new
test/c/program (or extend one that usesdb.h/DB_ENV), whereDB->cursor,DBC->get, andDB->statexist. That's where this coverage belongs. - If you specifically want to extend the 1.85 path, use only
get/put/del/seq/syncwith theR_*flags, and keep buffers caller-owned.
Happy to review a revised version. Closing for changes, not merging.
gburd
left a comment
There was a problem hiding this comment.
Thanks for the contribution — the intent (boundary conditions, cursor traversal, and stat coverage) is welcome. Unfortunately these additions can't land as written, because test/c/test_db185.c exercises the DB 1.85 compatibility API (dbopen() → struct __db), and the new code calls modern DB 4.x/5.x methods that do not exist on the 1.85 handle. From src/dbinc/db_185.in the 1.85 struct __db has exactly: close, del, get, put, seq, sync, fd — no cursor, no stat.
Blocking issues:
dbp->cursor(...)/cursor->c_get/c_put/c_close(won't compile). The 1.85 API has no cursor object; sequential traversal isdbp->seq(dbp, &key, &data, R_FIRST|R_NEXT).DBCand itsc_*methods are the modern API and aren't declared indb_185.h.dbp->stat(...)+DB_BTREE_STAT/DB_HASH_STAT/DB_RECNO_STAT(won't compile). The 1.85 handle has nostatmethod, and those stat structs belong to the modern API.__os_free(NULL, statp)— an internal engine symbol; a test intest/c/must not call__os_*. (Moot once #2 is dropped.)- 1 MB stack array (
char large_key[1024*1024]) — this repo's C-test convention forbids large stack arrays (stack overflow risk); use the heap. sprintf((char *)key.data, ...)after aget/c_getwrites into DB-owned memory returned by the previous call — never write into memory Berkeley DB owns; andkey.datamay be NULL there.char small_key[1] = ""can't hold the terminating NUL; and DB error codes are returned directly (don'tstrerror(errno)on them).
Suggested path: retarget this coverage at the modern API — the existing test/tcl suite (e.g. test001 for put/get/boundary, cursor tests, statprint001 for stat) already covers most of it, or add a C driver under test/c/ that opens a real DB_ENV/DB handle. If you specifically want 1.85-compat coverage, use seq() (there's no cursor/stat in 1.85). Happy to point at the right harness. Closing for now since it can't compile against the 1.85 header; please reopen a retargeted version.
Added the processing of boundary conditions for the new database, the complete operation process of cursors, and the test cases for database statistics information.